import time
from PocketCube import PocketCube

"""
这是测试程序，请将测试程序和PocketCube.py放在同一个路径下，直接右键运行即可。

请注意，您的魔方颜色的初始化一定要和测试案例相同，遵循以下规则：

Front   正面    (R)Red
Back    背面    (O)Orange
Up      上面    (W)White
Down    下面    (Y)Yellow
Left    左面    (G)Green
Right   右面    (B)Blue

"""

TestCases = {
    "case1": {
        "input": "UR'2U'L2",
        "output": "      Y      \n  Y       Y  \nO     W     O\n    R   B    \nB           O\n    G   O    \n"
    },
    "case2": {
        "input": "D2LB'FL'R",
        "output": "      W      \n  O       W  \nG     R     O\n    B   W    \nG           R\n    B   W    \n"
    },
    "case3": {
        "input": "FB2U'F2DU",
        "output": "      B      \n  B       Y  \nY     G     G\n    R   W    \nB           B\n    R   Y    \n"
    },
    "case4": {
        "input": "FB2D'RFD'ULR",
        "output": "      B      \n  B       W  \nR     G     G\n    O   Y    \nY           O\n    B   Y    \n"
    },
    "case5": {
        "input": "D'L'R2FB'U'DF2U'",
        "output": "      R      \n  G       B  \nW     B     W\n    O   W    \nG           G\n    O   W    \n"
    },
    "case6": {
        "input": "D'R2FUF'D'L2FUD",
        "output": "      B      \n  W       W  \nR     W     B\n    O   G    \nY           G\n    W   B    \n"
    },
}

if __name__ == '__main__':

    TimeUses = []
    correct_times = 0
    for caseName, body in TestCases.items():

        print(f"测试用例 - {caseName}  -----------------------")

        start_time = time.perf_counter()

        pocketCube = PocketCube()
        pocketCube.act_formula(body['input'])
        yourAns = pocketCube.show_front_up_right_view()

        end_time = time.perf_counter()

        print(f"你的答案\n\n{yourAns}\n")

        if yourAns == body['output']:
            print("正确！！！！")
            correct_times += 1
        else:
            print("错误！！！！")
            print(f"正确答案\n\n{body['output']}\n")

        elapsed_time = end_time - start_time
        TimeUses.append(elapsed_time)

        print(f"用时：{elapsed_time:.6f} 秒\n")

    print(f"{'-'*80}\n平均用时：{sum(TimeUses) / len(TimeUses):.6f} 秒")
    print(f"正确率：{correct_times / len(TestCases) * 100} %")

